package Application.LayerImage;

import javafx.scene.image.WritableImage;
import javafx.scene.image.Image;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

/**
 * 图片类
 * 可读写像素
 */
public class LayerImage {
    // 包装了此类
    private WritableImage img;

    public LayerImage(int width, int height ,WritableImage ... writableImages) {
        if(writableImages.length==0){
            img = new WritableImage(width, height);
        }else{
            img = writableImages[0];
        }

    }

    // 设置像素argb
    public void setPixelArgb(int x, int y, int argb) {
        //System.out.println(argb);
        img.getPixelWriter().setArgb(x, y, argb);
        //System.out.println(img.getPixelReader().getColor(x, y).getBlue());
    }

    // 设置像素Color
    public void setPixelColor(int x, int y, Color color) {
        img.getPixelWriter().setColor(x, y, color);
        //System.out.println(img.getPixelReader().getColor(x, y));
    }

    // 获取像素argb
    public int getPixelArgb(int x, int y) {
        return img.getPixelReader().getArgb(x, y);
    }

    // 获取像素Color
    public Color getPixelColor(int x, int y) {
        return img.getPixelReader().getColor(x, y);
    }

    public WritableImage getWritableImage() {
        return img;
    }

    public int getHeight() {
        return (int)img.getHeight();
    }

    public int getWidth() {
        return (int)img.getWidth();
    }
//    public boolean render(Canvas view) {
//        try {
//            GraphicsContext dc = view.getGraphicsContext2D();
//            return true;
//        } catch(Exception e) {
//            return false;
//        }
//    }
}
